<style>
    .layui-form .layui-form-item .layui-inline{
        padding-left: 5px;
    }
    .layui-form .layui-form-item .layui-inline input{
        width: 180px;
    }
</style>
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <input type="text" name="user_name" lay-verify="title" placeholder="User Name" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" name="user_memo" lay-verify="title" placeholder="User Memo" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" name="desc" lay-verify="title" placeholder="Desc" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" name="check_num" lay-verify="title" placeholder="Check Num" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" name="trn" lay-verify="title" placeholder="Trn" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-inline">
            <input type="text" name="datetime" id="datetime" placeholder="start_time _ end_time" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <select name="status" >
                <option value="">Please Select status</option>
                <option value="0">Pending</option>
                <option value="1">Completed</option>
                <option value="2">Failed</option>
            </select>
        </div>
        <div class="layui-inline">
            <input type="text" name="amount" id="amount" placeholder="$ 0.00" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-inline">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
            </div>
        </div>
    </div>
</form>
<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script>
    layui.use(['form', 'laydate', 'table',], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格
        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        var tableIn = table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            url: "{:url('balance/fundingDeb')}",
            id: 'balanceTable',
            cols: [[
                { type: 'numbers'},
                { field: 'user_num',  align: 'center', title: 'UserMemo',width: 80},
                { field: 'username',  align: 'left', title: 'UserName',width: 120},
                { field: 'check_num',  align: 'center', title: 'Check Num',width: 110},
                { align: 'center', title: 'Initiated Date' , width: 160,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { align: 'center', title: 'Posting Date' , width: 160,
                    templet: function (d) {
                        var utime = d.utime;
                        if(utime == null){
                            return ' -- ';
                        }else{
                            return layui.util.toDateString(utime * 1000, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                },
                { field: '', align: 'center', title: 'Type' ,width:80,
                    templet: function (d) {
                        const type_name = d.type;
                        if(type_name == 1){
                            return '<font color="red">Debit</font>';
                        }else{
                            return '<font color="green">Credit</font>';
                        }
                    },totalRowText:'Total Amount:'
                },
                {field: 'amount', title: 'Amount($)', align:"right",width:120,
                    style:'color:#FF5722;font-weight:bold',totalRow: true},
                { field: '', align: 'right', title: 'Balance($)' ,
                    style:'color:#FF5722;font-weight:bold',width:120,
                    templet: function (d) {
                        const balance = d.balance;
                        return balance;
                        // if(balance != 0){
                        //
                        // }else{
                        //     return ' -- ';
                        // }
                    }
                },
                { field: 'desc',  align: 'left', title: 'Description'},
                { field: 'remark',  align: 'center', title: 'Failed Remark'},
                { field: 'trn',  align: 'left', title: 'Trn',width: 120},
                { field: 'msg',  align: 'left', title: 'Remark'},
                { field: '', align: 'center', title: 'Status',width:100,
                    templet: function (d) {
                        const check_status = d.check_status;
                        if(check_status == '1'){
                            return '<font color="green">Completed</font>';
                        }else if(check_status == '2'){
                            return '<font color="red">Failed</font>';
                        }else{
                            return '<font color="#a9a9a9">Pending</font>';
                        }
                    }
                },
                { field: 'option', title: 'Option',width:80,
                    templet: function (d) {
                        var html ="";
                        html +='<a class="layui-btn layui-btn-xs editRemark" data-id="' + d.id + '">Remark</a>';
                        return html;
                    }, align: 'center'
                }
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100 , 500 , 1000]
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //余额编辑
        $(document).on('click', '.editRemark', function () {
            var id = $(this).attr('data-id');
            JsGet("{:url('fundsRemark')}?id="+id, function(e){
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: 'Edit Remark',
                        area: ['500px', '466px'], //宽高
                        content: e.datas,
                        btn:['Confirm','Close'],
                        yes:function (index,layero) {
                            var thedata = $('.operationForm').serialize();
                            var remark   = $("#remark").val();
                            if (remark == '' || !remark) {
                                layer.msg("Please input in Remark" , {icon:2,time:1500});
                                return false;
                            }
                            JsPost('{:url("fundsRemark")}', thedata,function (re) {
                                if(re.code >0){
                                    layer.msg(re.msg , {icon:1,time:1500});
                                    layer.close(index);
                                    tableIn.reload({
                                        page:{
                                            curr :1
                                        }
                                    });
                                }else{
                                    layer.msg(re.msg, {icon:2,time:1500});
                                }
                            });
                        }
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });
    });
</script>